import streamlit as st
import pandas as pd
import datetime

st.set_page_config(
    page_title="2.1NR",
    page_icon="✔",
    layout="wide",
    initial_sidebar_state="auto"
)

# st.balloons()

df = pd.read_excel('./output/21NR.xlsx')
df['开通日期'] = df['开通日期'].apply(str)
df['开通日期'] = df['开通日期'].apply(lambda x:x.split(' ')[0]) #YYYY/MM/DD 00:00:00

st.title(':violet[开通量统计]')
download_button = st.download_button('导出', df.to_csv(index=False).encode('utf-8-sig'), '21NR.csv', 'text/csv')

if download_button:
    st.toast('导出成功!')

delta = datetime.timedelta(days=1, seconds=0, microseconds=0, milliseconds=0, minutes=0, hours=0, weeks=0)

col11, col22, col33, col44, col55, col66, col77, col88 = st.columns(8)
with col88:
    d = st.date_input('')
    d_pre = str(d - delta)
    d = str(d)

with col11:
    st.metric('总齐套开通数', len(df.query(f"开通日期=='{d}'")), len(df.query(f"开通日期=='{d}'"))-len(df.query(f"开通日期=='{d_pre}'")))

col1, col2 = st.columns(2)
with col1:
    with st.form('form1'):
        st.header('中通')
        df1 = df.query(f"建设单位=='中通' & 开通日期=='{d}'")[['RRU名称', '资产序列号']]
        st.dataframe(df1,hide_index=True,width=1000)
        st.form_submit_button(label=f'{len(df1)}台',disabled=False)

with col2:
    with st.form('form2'):
        st.header('市工程')
        df2 = df.query(f"建设单位=='市工程' & 开通日期=='{d}'")[['RRU名称', '资产序列号']]
        st.dataframe(df2,hide_index=True,width=1000)
        st.form_submit_button(label=f'{len(df2)}台',disabled=False)

col3, col4 = st.columns(2)

with col3:
    with st.form('form3'):
        st.header('中通建')
        df3 = df.query(f"建设单位=='中通建' & 开通日期=='{d}'")[['RRU名称', '资产序列号']]
        st.dataframe(df3,hide_index=True,width=1000)
        st.form_submit_button(label=f'{len(df3)}台',disabled=False)

with col4:
    with st.form('form4'):
        st.header('长讯')
        df4 = df.query(f"建设单位=='长讯' & 开通日期=='{d}'")[['RRU名称', '资产序列号']]
        st.dataframe(df4,hide_index=True,width=1000)
        st.form_submit_button(label=f'{len(df4)}台',disabled=False)
